package com.yuyou.fn.report.service.impl;

import com.github.wens.framework.service.impl.SuperServiceImpl;
import com.github.wens.mybatisplus.examples.Example;
import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.common.exception.BusException;
import com.yuyou.fn.common.util.CriteriaUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.report.entity.ClassLectureDetail;
import com.yuyou.fn.report.mapper.ClassLectureDetailMapper;
import com.yuyou.fn.report.service.IClassLectureDetailService;
import com.yuyou.fn.report.vo.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * ClassLectureDetail 表数据服务层接口实现类
 *
 */
@Service
public class ClassLectureDetailServiceImpl extends SuperServiceImpl<ClassLectureDetailMapper, ClassLectureDetail,Long> implements IClassLectureDetailService {

    @Override
    public List<ClassLectureGroupDetailVo> findClassLectureGroupDetail(List<Long> periodIds,List<Long> busTeamIds,List<Long> gradeIds,ClassLectureDetailQueryVo classLectureDetailQueryVo, int start, int end) {

        return autoMapper.findClassLectureGroupDetail(periodIds,gradeIds,classLectureDetailQueryVo,busTeamIds,start,end);
    }

    @Override
    public Integer countClassLectureGroupDetail(List<Long> periodIds,List<Long> busTeamIds,List<Long> gradeIds,ClassLectureDetailQueryVo classLectureDetailQueryVo) {
        return autoMapper.countClassLectureGroupDetail(periodIds,gradeIds,classLectureDetailQueryVo,busTeamIds);
    }

    @Override
    public List<ClassLectureDetail> findByQueryVo(List<Long> periodIds,List<Long> busTeamIds,List<Long> gradeIds,ClassLectureDetailQueryVo classLectureDetailQueryVo) {
        Example<ClassLectureDetail> example=ClassLectureDetail.createExample();
        Example.Criteria criteria=example.createCriteria();
        CriteriaUtils.fillCondition(criteria,classLectureDetailQueryVo);
        if (Utils.checkListNotEmpty(busTeamIds)){
            criteria.andIn("busTeamId",busTeamIds);
        }
        if (Utils.checkListNotEmpty(periodIds)){
            criteria.andIn("periodId",periodIds);
        }
        if (Utils.checkListNotEmpty(gradeIds)){
            criteria.andIn("gradeId",gradeIds);
        }
        example.orderBy("classDate");
        return this.findListByExample(example);
    }

    @Override
    public List<ClassLectureDayDetailVo> findDayLectureDetail(ClassLectureDetailQueryVo classLectureDetailQueryVo, List<Long> busTeamIds) {
        return this.autoMapper.findDayLectureDetail(classLectureDetailQueryVo,busTeamIds);
    }

    @Override
    public Page<ClassLectureDetail> findPageByPeriodIds(List<Long> periodIds, List<Long> busTeamIds, List<Long> gradeIds, List<Long> subjectIds, ClassLectureDetailQueryVo classLectureDetailQueryVo, int pageNo, int pageSize) {
        if (Utils.checkListEmpty(periodIds)){
            throw new BusException("期数不能为空");
        }
        Example<ClassLectureDetail> example=ClassLectureDetail.createExample();
        Example.Criteria criteria=example.createCriteria();
        CriteriaUtils.fillCondition(criteria,classLectureDetailQueryVo);
        if (Utils.checkListNotEmpty(busTeamIds)){
            criteria.andIn("busTeamId",busTeamIds);
        }
        if (Utils.checkListNotEmpty(periodIds)){
            criteria.andIn("periodId",periodIds);
        }
        if (Utils.checkListNotEmpty(gradeIds)){
            criteria.andIn("gradeId",gradeIds);
        }
        example.orderBy("classDate");
        return this.findPageByExample(example,pageNo,pageSize);
    }

    @Override
    public List<EmployeeCourseVo> findEmployeeCourse(ClassLectureDetailQueryVo classLectureDetailQueryVo) {
        return this.autoMapper.findEmployeeCourse(classLectureDetailQueryVo);
    }

    @Override
    public List<TeacherSubjectSituationVo> findTeacherSubjectDetailList(ClassLectureDetailQueryVo classLectureDetailQueryVo, int start, int end) {
        return autoMapper.findTeacherSubjectDetailList(classLectureDetailQueryVo,start,end);
    }

    @Override
    public Integer countTeacherSubjectDetail(ClassLectureDetailQueryVo classLectureDetailQueryVo) {
        return autoMapper.countTeacherSubjectDetail(classLectureDetailQueryVo);
    }

    @Override
    public Page<TeacherSubjectSituationVo> findTeacherSubjectDetailPage(ClassLectureDetailQueryVo classLectureDetailQueryVo, int pageNo, int pageSize) {
        Page<TeacherSubjectSituationVo> page=new Page<>(pageNo,pageSize);
        List<TeacherSubjectSituationVo> teacherSubjectDetailList = this.findTeacherSubjectDetailList(classLectureDetailQueryVo, (pageNo - 1) * pageSize, pageSize);
        Integer total=this.countTeacherSubjectDetail(classLectureDetailQueryVo);
        page.setRecords(teacherSubjectDetailList);
        page.setTotal(total);
        return page;
    }
}